﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SDM.ExamPlanner.DALC;
using SDM.ExamPlanner.DTO;

namespace SDM.ExamPlanner.Test
{
    [TestClass]
    public class RepositoryTest : BaseTest
    {
        [TestMethod]
        public void FindTest()
        {
            // Assign
            var educationRepository = new DataRepository<Education>();

            // Act
            educationRepository.RegisterNew(new Education { Name = "Computer Science" });
            educationRepository.RegisterNew(new Education { Name = "Multimedia Design" });
            educationRepository.SaveChanges();
            var educations = educationRepository.Find();

            // Assert
            Assert.AreEqual(2, educations.Count());
        }

        [TestMethod]
        public void SaveTest()
        {
            // Assign
            var educationRepository = new DataRepository<Education>();
            var education = new Education {Name = "Computer Science"};
            
            // Act
            educationRepository.RegisterNew(education);
            educationRepository.SaveChanges();

            // Assert
            Assert.AreNotEqual(0, education.Id);
        }

        [TestMethod]
        public void DeleteTest()
        {
            // Assign
            var educationRepository = new DataRepository<Education>();
            var education = new Education {Name = "Computer Science"};
            
            // Act
            educationRepository.RegisterNew(education);
            educationRepository.SaveChanges();
            educationRepository.RegisterDeleted(education);
            educationRepository.SaveChanges();

            // Assert
            Assert.IsFalse(educationRepository.Find().Any());
        }
    }
}
